package com.qqtech.qquan.circle.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.activity.service.ActivityBaseService;
import com.qqtech.qquan.circle.enums.CircleBaseStatusDictEnum;
import com.qqtech.qquan.circle.model.CircleBaseVo;
import com.qqtech.qquan.circle.model.CircleInfo;
import com.qqtech.qquan.circle.model.CircleInfoQuery;
import com.qqtech.qquan.circle.model.CircleInfoVo;
import com.qqtech.qquan.circle.service.CircleBaseService;
import com.qqtech.qquan.circle.service.CircleInfoService;
import com.qqtech.qquan.circle.service.CircleMemberService;
import com.qqtech.qquan.user.model.UserBaseVo;
import com.qqtech.qquan.user.service.UserBaseService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/circle/info")
public class CircleInfoController extends BaseWebController<CircleInfo, CircleInfoQuery> {
	@Resource
	private CircleInfoService circleInfoService;
	@Resource
	private CircleBaseService circleBaseService;
	@Resource
	private CircleMemberService circleMemberService;
	@Resource
	private UserBaseService userBaseService;
	@Resource
	private ActivityBaseService activityBaseService;
	
	@Override
	protected BaseService<CircleInfo> getBaseService() {
		return circleInfoService;
	}
	
	/**
	 * 圈子资料
	 * @param circleQuery
	 * @return
	 */
	@RequestMapping(value = "/moreInfo")
	@ResponseBody
	public Result moreInfo(@RequestBody CircleInfoQuery  circleInfo){		
		Result result = new Result();		
		Integer circleId = circleInfo.getId();//前端-参数
		if(circleId==null){
			result.addErr("圈子Id信息为空！");
			return result;
		}
		CircleBaseVo circleBaseVo = circleBaseService.getById(circleId);
		CircleInfoVo circleInfoVo = circleInfoService.getById(circleId);
		if(circleBaseVo==null || circleInfoVo == null){
			result.addErr("找不到该圈子！");
			return result;
		}else if(circleBaseVo.getStatus()!=CircleBaseStatusDictEnum.NORMAL.getCode()){
			result.addErr("该圈子已不存在【已删除或已解散】！");
			return result;
		}else{
			Integer circleCreatorId = circleBaseVo.getCreatorId();
			UserBaseVo userVo= userBaseService.getById(circleCreatorId);
			if(userVo!=null){
				circleBaseVo.setCreatorName(userVo.getNick());//圈主-呢称
				circleBaseVo.setCreatorLogo(userVo.getLogo());
			}
			if(circleBaseVo.getIsOfficial()){
				circleBaseVo.setCreatorName("系统管理员");
			}
			
			result.put("circleBase", circleBaseVo);
			result.put("circleInfo", circleInfoVo);
		}
		return result;
	}
}
